home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
program
/
4th86_v4.zip
/
TUTORIAL.TXT
< prev
next >
Wrap
Text File
|
1994-01-25
|
10KB
|
364 lines
splitscreen
~
12
splitscreen
w1
logo
w2init
w1
Welcome to 4th_86 implementation of the FORTH language.
It is recommended that you print out and read the file INTRO.4TH as this
will explain the concept of FORTH as an operating environment. However --
if you prefer the "learn by doing" approach -- carry on with this tutorial.
Use keys 4 F2 N and 4 F1 N to page forward and back. At the last page F2
will cycle you back to the beginning page. F1 action ceases at page 1.
To leave 4th_86 and return to DOS type 4 BYE N
$
~
w1init
w2
The blue window is used for tutorial text. The Brown window is for you to
enter commands and view results.
The power of 4th_86 lies in the "integrated development environment" FORTH
as a language permits. Do not be discouraged initially by the "strange"
symbols used -- or the "reverse" method of inputting variables and
parameters. You will soon adapt to this as easily as you could to i++ and
++i or the perverse niceties of the semicolon in the C language -- or to
the complex printf style formatting commands in Pascal; Fortran; or C.
w2init
w1
Try typing each of the following commands as you would if you were in MsDos
**NOTE** although commands are shown in upper case ( capital ) letters you
can type them in either upper or lower case. 4th_86 is not case sensitive.
4 DIR N 4 DIR \*.SYS N 4 5 SECDELAY N 4 TM N
If you get in trouble -- use keys 4 F2 N or 4 F1 N to get back to
the tutorial and try again
w1
$
~
w1init
13
w2
Now let's try two more forth WORDS which will give you some background
details -- but will temporarily erase the colored windows.
Do not panic when all the tutorial instructions disappear!! You can easily
get them back by using keys 4 F1 4 F2 -- or if that doesn't
work, by typing 4 HELP
w2init
w1
So let's try it --- type each of the following commands -- again just as
you would if you were in MsDos
4 INFO N 4 INTRO N
w1
$
~
w2
2
Here is part of the the 4 STATUS display
w1
status
$
~
splitscreen
w1init
w2
When you are using 4th_86 seriously as a programming tool -- you will not
usually be working in a colored window -- or half screen environment --
though you can if you so choose.
In this exercise; once again all the tutorial text will disappear -- but
this time 4 F1 4 F2 will not function. Only 4 HELP
will return you to the tutorial text.
w2init
w1
Write down the following commands to try once you exit windowed mode
4 DIR N 4 STATUS N 4 DDICT N 4 FILES N
4 DD GOTOXY N 4 DD SECDELAY N
Then type 4 FULLSCREEN N to leave tutorial mode.
Remember -- enter 4 HELP N to return
$
~
w1init
10
w2
4th_86 also allows you to use your own favorite DOS editor with a
considerable degree of automation. You will need to configure the file
EDITR.BAT to make this work - so let's leave that till you've read
INTRO.4TH.
FORTH is both an INTERPRETER and a COMPILER. It's much much more than
BASIC is -- but let's use the concepts of BASIC and C as a starting
point.
w1
C version Basic version
--------- -------------
main(void) 10 for i = 1 to 10
{ 20 print i
int i; 30 next
for (i=1; i<=10; i++ )
printf ("%d \n", i) ; Forth version
} -------------
: test1 10 0 do i . crlf loop ;
$
~
w1init
9
w2
C version Basic version
--------- -------------
main(void) 10 for i = 1 to 10
{ 20 print i
int i; 30 next
for (i=1; i<=10; i++ )
printf ("%d \n", i) ; Forth version
} -------------
: test1 10 0 do i . crlf loop ;
w1
The C version has to be compiled and linked with a library to form an EXE
file before the program can be executed. The file can be named TEST1.EXE.
The BASIC version can be run in INTERPRETER mode by typing the command RUN.
It can be saved as a file TEST1.BAS -- but this is not an executable file.
If a COMPILER rather than an INTERPRETER is used -- an EXE file can be
created -- but BASIC interpreters and compilers are separate utilities.
The FORTH version is COMPILED **as it is being written**. It has a name
TEST1 and can be immediately executed by typing TEST1. It can be saved
either as an executable file TEST1.COM -- or source TEST1.4TH
$
~
split
w2
9
You could now type in the following four FORTH definitions
4: test1 5 0 do i . crlf loop ; 4: test2 15 0 do i . tab 3 +loop ;
4: test3 10 0 do i . 2 spcs loop ; 4: test4 20 5 do i . loop ;
However we have done it for you in a file called EXAMPLE1.4TH
so all you need do is type 4 FLOAD EXAMPLE1.4TH
and then execute each word in turn by typing 4TEST1 4TEST2 etc
$
~
split
w1
23
Note that definitions can continue over several lines
: test1
10 0
do
i . crlf
loop
;
So that once you have entered a COLON sign -- 4th_86 will attempt to compile
every statement you make -- up to the point at which it detects a SEMICOLON
This causes few problems if you forget the semicolon -- because 4th_86 will
rapidly be given some text it doesn't recognise -- at which point it will
give an error message.
w1
$
~
split
w1
23
The same applies to comment delimiters -- a CR does NOT end a comment. This
can cause mysterious hangups as text you thought was being entered as a
definition is being treated as an ongoing comment.
: test5 20 0 do i . loop ;
( the above was test 5
: test6 15 0 do i . 3 +loop ;
( that was test 6 )
test5 has been entered as a definition. test6 however -- and any more
text that is typed in -- is ignored by 4th_86 as a comment; because the
right hand ) delimiter after " was test 5 " has been missed out.
You must take care to ensure brackets match -- as do colons and
semicolons. If 4th_86 appears to have gone to sleep -- it is most likely
due to an unclosed comment string.
w1
$
~
w1init
10
w2
The same care must be taken to match double-quote marks " in strings
Load the file EXAMPLE2 by typing 4 FLOAD EXAMPLE2.4TH
Once you have loaded the file try out the words
4 HEADER 4 FOOTER 4 DOLOOP 4 DOLOOPTEST
As you have not yet configured EDITR.BAT -- you can use the command
4 TYPE EXAMPLE2.4TH if you want to view the definitions again
w1
$
~
w1init
10
w2
Practice printing out some strings. It can be done in IMMEDIATE
mode ( ie -- not within a word definition ) just as in BASIC.
Take care to leave a space after the first quote mark
" this is a test" ." will print correctly
"this is a test" ." will give an error message
w1
$
~
w1init
10
w2
Note that control characters such as LF CR TAB etc can be inserted
inline provided they are enclosed by up-arrow delimiters
" this is ^9^ a test ^0dh 0ah^ to see ^13 10^ what happens " ."
The 9 represents TAB. CR is either 0dh ( hex ) or 13 ( decimal )
LF is either 0ah ( hex) or 10 ( decimal)
w1
$
~
w2
2
Here are the definitions you've entered to date.
ddict
$
~
splitscreen
w2
10
Go back to the previous screen and select a word somewhere in the middle of
those listed under USER DEFINITIONS -- then return to this screen
Let's suppose the word you chose was HEADER
type 4 FORGET HEADER
and again return to the previous screen
w1
You will find that HEADER and all the words defined after it have
now been deleted from 4th_86.
$
~
splitscreen
w2
19
Now let's define a new word -- type in
4 : new-word " this is a test " ." ;
you can make sure it works by typing 4 new-word
Now let's try to re-define the same word
4 : new-word " this is not another test " ." ;
when you get asked if you want to redefine -- answer Y
Now test by again typing 4 new-word
type 4 forget new-word and then 4 new-word
you will see that the original definition has been restored
w1
$
~
splitscreen
w2
10
by now you should be reasonably comfortable with how 4th_86 functions
( see next screen for window manipulation commands )
repeat the last screen if unsure -- and then type
4 w2 followed by 4 splitat 0 and
4 ddict
w1
Now define and redefine some words -- use DDICT to examine the
dictionary -- FORGET some words and use DDICT again.
If you're feeling really brave, leave thhis tutorial by
typing 4 fullscreen N and enjoy the freedom of a full size screen.
Configure EDITR.BAT and ASMBL.BAT and work through the examples
in the documentation.
You can always return to windowed mode by the words
4 splitscreen N or 4 help N
w1
$
~
splitscreen
w2
10
W1 places cursor in upper window
W2 places cursor in lower window
W1INIT and W2INIT clear windows
SPLIT divides windows equally mid-screen
SPLITAT N divides windows at line N
( if N > 23 it's truncated to 23 )
SPLITSCREEN is the same as SPLIT
FULLSCREEN is the same as UNSPLIT
w1
The source code for the tutorial / windows is included
as 7TUT04.4TH
All source code is pure ascii and can be printed as-is
or edited with any ASCII type editor.
examine the code to get further ideas of how to use FORTH
$